package com.lizemin.common;

import lombok.Data;

/**
 * @author lzm
 * @date 2025/4/19 22:39
 * @description
 */
@Data
public class ApiResponse {

    /**
     * 状态码
     */
    private Integer code;

    /**
     * 状态信息
     */
    private String message;

    /**
     * 数据
     */
    private Object data;

    /**
     * 构造响应成功
     *
     * @param data 数据
     * @return 响应成功的结果
     */
    public static ApiResponse success(Object data) {
        ApiResponse resp = new ApiResponse();
        resp.code = 200;
        resp.message = "success";
        resp.data = data;
        return resp;
    }

    public static ApiResponse success() {
        return success(null);
    }

    public static ApiResponse fail() {
        ApiResponse resp = new ApiResponse();
        resp.code = 500;
        resp.message = "fail";
        return resp;
    }

    public static ApiResponse fail(String message) {
        ApiResponse resp = new ApiResponse();
        resp.code = 500;
        resp.message = message;
        return resp;
    }

}
